home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug187 / datain.c < prev    next >
Text File  |  1985-12-30  |  1KB  |  55 lines

  1. /*@*****************************************************/
  2. /*@                                                    */
  3. /*@ datain - prototype input routine which reads       */
  4. /*@        transparently from either the keyboard      */
  5. /*@        or a file, but checks the keyboard for      */
  6. /*@        override on each call.                      */
  7. /*@                                                    */
  8. /*@   Usage:     datain();                             */
  9. /*@       returns an int sized char.                   */
  10. /*@                                                    */
  11. /*@*****************************************************/
  12.  
  13. int datain()
  14. {
  15.     int nc, c, kbdin();
  16.     unsigned i;
  17.  
  18.     if (IFd != -1) {
  19.         if ((c = kbdin()) == CMND) {
  20.             conout("\nFile Abort from Console \n",NORM);
  21.             fclose(IFd);
  22.             IFd = -1;
  23.             getchar();
  24.             return(c);
  25.         }
  26.         if ((c = getc(IFd)) == EOF) {
  27.             conout("\nEnd of File on ",NORM);
  28.             conout(Infile,NORM);
  29.             fclose(IFd);
  30.             IFd = -1;
  31.             return(kbdin());
  32.         }
  33.         else {
  34.             if (TrmMd) {
  35.                 if (c == SIMCTRL) {
  36.                     if ((nc = getc(IFd)) == EOF) {
  37.                         conout("\nPremature End of File on ",NORM);
  38.                         conout(Infile,NORM);
  39.                         fclose(IFd);
  40.                         IFd = -1;
  41.                         return(kbdin());
  42.                     }
  43.                     if (nc != c)
  44.                         c = 0xbf & nc;    /* convert to control character */
  45.                 }
  46.                 for (i=0; i <10000; i++) ;
  47.             }
  48.             return(c);
  49.         }
  50.     }
  51.     else
  52.         return(kbdin());
  53. }
  54.  
  55.